function loadUserEditButton() {
	$("#page-wrapper").load("parts/userEdit.html");
}
function loadPasswdEditButton() {
	$("#page-wrapper").load("parts/passwdEdit.html");
}

function dopasswdEditCon() {
	var currentPasswd = $("#currentPasswd").val();
	var newPasswd = $("#newPasswd").val();
	var newPasswd2 = $("#newPasswd2").val();

	if (newPasswd == "") {
		alert("用户名或密码不能为空");
		return;
	} else if (newPasswd != newPasswd2) {
		alert("输入的新密码不一致，请重新输入！");
		return;
	} else {
		request = new Object();
		request.operation = "chgPasswd";
		request.jsonObject = new Object();
		request.jsonObject.userId = thisUser.id;
		request.jsonObject.curPasswd = currentPasswd;
		request.jsonObject.newPasswd = newPasswd;
		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					$("#showUser").html(resp.entity.name + resp.entity.phone);
					if (resp.entity != null) {
						thisUser = resp.entity;
						alert("修改密码成功，返回我的工作台！");
						$("#page-wrapper").load("parts/workSpace.html");
					} else {
						alert("修改密码失败，错误原因：" + resp.message);
					}
				} else {
					alert("修改密码失败，错误原因：" + resp.message);
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
	// alert("新密码为："+thisUser.passwd);
}
// function checkLeave() {
// alert("刷新");
// }

function loadUserEdit() {
	request = new Object();
	request.operation = "getTeam";
	request.jsonObject = new Object();
	request.jsonObject.teamId = thisUser.teamId;
	$
			.post(
					"Gate",
					{
						req : JSON.stringify(request)
					},
					function(data, status) {
						if (status == "success") {
							var resp = eval("(" + data + ')');
							if (resp.status == 0) {
								$("#showUser").html(resp.entity.name);
								if (resp.entity != null) {
									thisTeam = resp.entity;
									document.getElementById('userEditAccount').innerText = thisUser.account;
									document.getElementById('userEditTeamName').innerText = resp.entity.teamName;
									$("#userEditName").val(thisUser.name);
									$("#userEditPhone").val(thisUser.phone);
									$("#userEditEmail").val(thisUser.email);
									$("#userEditSex").val(thisUser.sex);
									var imgTmp = "<img src=\""
											+ thisUser.avatar
											+ "\"width=\"100\" height=\"100\"/>";
									// $("#avatarImg").innerHTML=imgTmp;
									document.getElementById('avatarImg').innerHTML = imgTmp;

									$("#userEditAvatar").val(thisUser.avatar);
								} else {
									document.getElementById('userEditAccount').innerText = thisUser.account;
									$("#userEditTeamName").val("");
									$("#userEditName").val(thisUser.name);
									$("#userEditPhone").val(thisUser.phone);
									$("#userEditEmail").val(thisUser.email);
									$("#userEditSex").val(thisUser.sex);
									var imgTmp = "<img src=\""
											+ thisUser.avatar
											+ "\"width=\"100\" height=\"100\"/>";
									$("#avatarImg").innerHTML(imgTmp);
									alert("GetTeam返回结果为空！");
								}
							} else {
								alert("GetTeam失败，错误原因：" + resp.message
										+ ",返回首页！");
								$("#page-wrapper").load("parts/workSpace.html");
							}
						} else {
							alert("HTTP请求异常，请重新登陆！");
							self.location = "login.html";
						}
					});
}

function doUserEditCon() {
	var userEditName = $("#userEditName").val();
	var userEditPhone = $("#userEditPhone").val();
	var userEditEmail = $("#userEditEmail").val();
	var userEditSex = $("#userEditSex").val();
	var userEditAvatar = $("#userEditAvatar").val();

	if (userEditName == "") {
		alert("用户名不能为空！");
		return;
	} else if (userEditSex == "") {
		alert("性别不能为空！");
		return;
	} else {
		request = new Object();
		request.operation = "chgUser";
		request.jsonObject = new Object();
		request.jsonObject.userId = thisUser.id;
		request.jsonObject.account = thisUser.account;
		request.jsonObject.passwd = thisUser.passwd;
		request.jsonObject.createTime = thisUser.createTime;
		request.jsonObject.isManager = thisUser.isManager;
		request.jsonObject.teamId = thisUser.teamId;
		request.jsonObject.name = userEditName;
		request.jsonObject.phone = userEditPhone;
		request.jsonObject.email = userEditEmail;
		request.jsonObject.sex = userEditSex;
		request.jsonObject.avatar = userEditAvatar;
		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					$("#showUser").html(resp.entity.name);
					if (resp.entity != null) {
						thisUser = resp.entity;
						alert("修改个人信息成功，返回我的工作台！");
						$("#page-wrapper").load("parts/workSpace.html");
					} else {
						alert("修改密码失败，错误原因：" + resp.message);
					}
				} else {
					alert("修改密码失败，错误原因：" + resp.message);
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}

function doCan() {
	$("#page-wrapper").load("parts/workSpace.html");
}

function doAlert() {
	alert(thisUser.name);
}
// 用于passwdEdit判断密码强度
function CheckIntensity(pwd) {
	var Mcolor, Wcolor, Scolor, Color_Html;
	var m = 0;
	// 匹配数字
	if (/\d+/.test(pwd)) {
		debugger;
		m++;
	}
	;
	// 匹配字母
	if (/[A-Za-z]+/.test(pwd)) {
		m++;
	}
	;
	// 匹配除数字字母外的特殊符号
	if (/[^0-9a-zA-Z]+/.test(pwd)) {
		m++;
	}
	;

	if (pwd.length <= 6) {
		m = 1;
	}
	if (pwd.length <= 0) {
		m = 0;
	}
	switch (m) {
	case 1:
		Wcolor = "pwd pwd_Weak_c";
		Mcolor = "pwd pwd_c";
		Scolor = "pwd pwd_c pwd_c_r";
		Color_Html = "弱";
		break;
	case 2:
		Wcolor = "pwd pwd_Medium_c";
		Mcolor = "pwd pwd_Medium_c";
		Scolor = "pwd pwd_c pwd_c_r";
		Color_Html = "中";
		break;
	case 3:
		Wcolor = "pwd pwd_Strong_c";
		Mcolor = "pwd pwd_Strong_c";
		Scolor = "pwd pwd_Strong_c pwd_Strong_c_r";
		Color_Html = "强";
		break;
	default:
		Wcolor = "pwd pwd_c";
		Mcolor = "pwd pwd_c pwd_f";
		Scolor = "pwd pwd_c pwd_c_r";
		Color_Html = "无";
		break;
	}
	document.getElementById('pwd_Weak').className = Wcolor;
	document.getElementById('pwd_Medium').className = Mcolor;
	document.getElementById('pwd_Strong').className = Scolor;
	document.getElementById('pwd_Medium').innerHTML = Color_Html;
}

// 组织管理，获得当前用户管理的组织
function loadTeamList() {
	// alert("加载List");
	request = new Object();
	request.operation = "getSubTeams";
	request.jsonObject = new Object();
	request.jsonObject.teamId = thisUser.teamId;
	$
			.post(
					"Gate",
					{
						req : JSON.stringify(request)
					},
					function(data, status) {
						if (status == "success") {
							var resp = eval("(" + data + ')');
							if (resp.status == 0) {
								$("#showUser").html(resp.entity.name);
								if (resp.entity != null) {
									subTeamList = resp.entity;
									var table_str = "";
									for (var i = 0; i < subTeamList.length; i++) {
										// alert(subTeamList[i].teamId);
										table_str = table_str
												+ "<tr class=\"odd gradeX\"><td class=\"center\">"
												+ subTeamList[i].teamId
												+ "</td><td class=\"center\">"
												+ subTeamList[i].teamName
												+ "</td><td class=\"center\">"
												+ subTeamList[i].upTeamId
												+ "</td><td class=\"center\">"
												+ subTeamList[i].upTeamName
												+ "</td><td><button type=\"submit\" class=\"btn btn-default\" onclick=doEditTeam("
												+ subTeamList[i].teamId
												+ ");>修改</button><button type=\"submit\" class=\"btn btn-default\" onclick=doDelTeam("
												+ subTeamList[i].teamId
												+ ");>删除</button>"
												+ "</td></tr>";
									}
									document.getElementById("tBody").innerHTML = table_str;
								} else {
									alert("GetSubTeams返回结果为空！");
								}
							} else {
								alert("GetSubTeams失败，错误原因：" + resp.message
										+ ",返回首页！");
								$("#page-wrapper").load("parts/workSpace.html");
							}
						} else {
							alert("HTTP请求异常，请重新登陆！");
							self.location = "login.html";
						}
					});
}

// 修改组织，打开页面，LOAD选中的待修改组织
function doEditTeam(teamId) {
	$("#page-wrapper")
			.load(
					"parts/teamManageEdit.html",
					function() {
						request = new Object();
						request.operation = "getTeam";
						request.jsonObject = new Object();
						request.jsonObject.teamId = teamId;
						$
								.post(
										"Gate",
										{
											req : JSON.stringify(request)
										},
										function(data, status) {
											if (status == "success") {
												var resp = eval("(" + data
														+ ')');
												if (resp.status == 0) {
													$("#showUser").html(
															resp.entity.name);
													if (resp.entity != null) {
														// alert(resp.entity.teamName);
														thisTeam = resp.entity;
														document
																.getElementById('teamManageEditTeamId').innerText = teamId;
														// alert("resp.entity.teamName"+resp.entity.teamName);
														$(
																"#teamManageEditTeamName")
																.val(
																		resp.entity.teamName);
														var table_str = "";
														var selectUpTeamId;
														if (teamId != thisUser.teamId) {
															table_str = "<option value=\"teamManageEditUpTeamNameDefalt\"></option>";
															for (var i = 0; i < subTeamList.length; i++) {
																// alert(subTeamList[i].teamId);
																if (teamId == subTeamList[i].teamId) {
																	selectUpTeamId = subTeamList[i].upTeamId;
																}
																table_str = table_str
																		+ "<option value=\""
																		+ subTeamList[i].teamId
																		+ "\">"
																		+ subTeamList[i].teamName
																		+ "</option>";
															}
															$(
																	"#teamManageEditUpTeamName")
																	.html(
																			table_str);
															$(
																	"#teamManageEditUpTeamName")
																	.val(
																			selectUpTeamId);
														} else {
															document
																	.getElementById("teamManageUp").innerHTML = "当前用户所在组织，无权限修改上级组织！<br /><br />";
														}
													} else {
														alert("GetTeam返回为空，返回首页！");
														$("#page-wrapper")
																.load(
																		"parts/workSpace.html");
													}
												} else {
													alert("GetTeam失败，错误原因："
															+ resp.message
															+ ",返回首页！");
													$("#page-wrapper")
															.load(
																	"parts/workSpace.html");
												}
											} else {
												alert("HTTP请求异常，请重新登陆！");
												self.location = "login.html";
											}
										});
					}

			);
}

// 删除组织
function doDelTeam(teamId) {
	// alert("加载List");
	var result = confirm("请确认删除ID为 " + teamId + " 的组织！");
	if (result) {
		request = new Object();
		request.operation = "delTeam";
		request.jsonObject = new Object();
		request.jsonObject.teamId = teamId;

		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					// $("#showUser").html(resp.entity.name);
					// alert("删除成功，返回组织管理！");
					$("#page-wrapper").load("parts/teamManage.html");
				} else {
					alert("删除组织失败，错误原因：" + resp.message);
					$("#page-wrapper").load("parts/teamManage.html");
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}

// teamManageEdit修改组织页面-确认修改
function doEditTeamCon() {
	var teamManageEditUpTeamId;
	var tempIdTmp = $('#teamManageEditTeamId').text();
	var teamManageEditTeamName = $("#teamManageEditTeamName").val();
	if (teamManageEditTeamName == "") {
		alert("组织名称不能为空！");
		return;
	} else if (tempIdTmp != thisUser.teamId) {
		teamManageEditUpTeamId = $("#teamManageEditUpTeamName").val();
		if (teamManageEditUpTeamId == "") {
			alert("上级组织名称不能为空！");
			return;
		}
	} else {
		for (var i = 0; i < subTeamList.length; i++) {
			if (subTeamList[i].teamId == tempIdTmp) {
				teamManageEditUpTeamId = subTeamList[i].upTeamId;
			}
		}
	}
	var result = confirm("请确认修改ID为" + tempIdTmp + "的组织！");
	if (result) {
		request = new Object();
		request.operation = "chgTeam";
		request.jsonObject = new Object();
		request.jsonObject.teamId = tempIdTmp;
		request.jsonObject.teamName = teamManageEditTeamName;
		request.jsonObject.upTeamId = teamManageEditUpTeamId;
		request.jsonObject.cityName = "na";
		request.jsonObject.cityId = 1;

		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					alert("修改成功，返回组织管理！");
					$("#page-wrapper").load("parts/teamManage.html");
				} else {
					alert("修改组织失败，错误原因：" + resp.message);
					$("#page-wrapper").load("parts/teamManage.html");
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}
// teamManageEdit 取消修改按钮
function doEditTeamCan() {
	$("#page-wrapper").load("parts/teamManage.html");
}

// 顶部返回组织管理主页
function loadNavTeamList() {
	$("#page-wrapper").load("parts/teamManage.html");
}

// 顶部加载 添加组织管理页面
function loadTeamManageAdd() {
	// alert("MMMMMM");
	$("#page-wrapper").load(
			"parts/teamManageAdd.html",
			function() {
				$("#SK").append("<option value=defaultSelect></option>");
				for (var i = 0; i < subTeamList.length; i++) {
					$("#SK").append(
							"<option value=" + subTeamList[i].teamId + ">"
									+ subTeamList[i].teamName + "</option>");
				}
				$("#SK").val(defaultSelect);
				// alert(table_str2);
			});
}

// teamManageAdd添加组织页面-确认
function doAddTeamCon() {
	var teamManageAddTeamName = $("#teamManageAddTeamName").val();
	var teamManageAddUpTeamId = $("#SK").val();
	if (teamManageAddTeamName == "") {
		alert("组织名称不能为空！");
		return;
	} else if (teamManageAddUpTeamId == "defaultSelect") {
		alert("上级组织名称不能为空！");
		return;
	} else {

		request = new Object();
		request.operation = "addTeam";
		request.jsonObject = new Object();
		// request.jsonObject.teamId = tempIdTmp;
		request.jsonObject.teamName = teamManageAddTeamName;
		request.jsonObject.upTeamId = teamManageAddUpTeamId;
		request.jsonObject.cityName = "na";
		request.jsonObject.cityId = 1;

		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					alert("添加组织 " + teamManageAddTeamName + " 成功!");
					$("#page-wrapper").load("parts/teamManage.html");
				} else {
					alert("添加组织失败，错误原因：" + resp.message);
					// $("#page-wrapper").load("parts/teamManage.html");
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}

// 用户管理页面加载用户列表
function loadMUserList() {
	request = new Object();
	request.operation = "getSubUsers";
	request.jsonObject = new Object();
	request.jsonObject.userId = thisUser.id;

	$.post("Gate", {
		req : JSON.stringify(request)
	}, function(data, status) {
		if (status == "success") {
			var resp = eval("(" + data + ')');
			if (resp.status == 0) {
				showTable(resp.entity);
				if (resp.entity != null) {
					subUserList = resp.entity;
				} else {
					alert("GetSubUsers返回结果为空！");
				}
			} else {
				alert("GetSubUsers失败，错误原因：" + resp.message + ",返回首页！");
				$("#page-wrapper").load("parts/workSpace.html");
			}
		} else {
			alert("HTTP请求异常，返回首页！");
			$("#page-wrapper").load("parts/workSpace.html");
		}
	});
}
// 用户管理-返回查询界面
function loadNavUserList() {
	$("#page-wrapper").load("parts/userManage.html");
}
// 用户管理-取消或者返回按钮
function doUserManageCan() {
	$("#page-wrapper").load("parts/userManage.html");
}

// 用户管理-加载用户添加界面，并初始化option选项
function loadUserManageAdd() {
	$("#page-wrapper")
			.load(
					"parts/userManageAdd.html",
					function() {

						request = new Object();
						request.operation = "getSubTeams";
						request.jsonObject = new Object();
						request.jsonObject.teamId = thisUser.teamId;
						$
								.post(
										"Gate",
										{
											req : JSON.stringify(request)
										},
										function(data, status) {
											if (status == "success") {
												var resp = eval("(" + data
														+ ')');
												if (resp.status == 0) {
													if (resp.entity != null) {
														subTeamList = resp.entity;
														$(
																"#userMAddUpTeamNameS")
																.append(
																		"<option value=defaultSelect></option>");
														for (var i = 0; i < subTeamList.length; i++) {
															$(
																	"#userMAddUpTeamNameS")
																	.append(
																			"<option value="
																					+ subTeamList[i].teamId
																					+ ">"
																					+ subTeamList[i].teamName
																					+ "</option>");
														}
														$("#userMAddIsManageS")
																.val("0");
														$(
																"#userMAddUpTeamNameS")
																.val(
																		defaultSelect);
													} else {
														alert("GetSubTeams返回结果为空！");
													}
												} else {
													alert("GetSubTeams失败，错误原因："
															+ resp.message
															+ ",返回首页！");
													$("#page-wrapper")
															.load(
																	"parts/workSpace.html");
												}
											} else {
												alert("HTTP请求异常，请重新登陆！");
												self.location = "login.html";
											}
										});
					});
}
// 管理员添加用户界面的确认按钮动作事件
function doUserMAddSubmitCon() {
	var userMAddAccount = $("#userMAddAccount").val();
	var userMAddPasswd = $("#userMAddPasswd").val();
	var userMAddName = $("#userMAddName").val();
	var userMAddUpTeamId = $("#userMAddUpTeamNameS").val();
	var userMAddIsManageS = $("#userMAddIsManageS").val();
	var userMAddSexS = $("#userMAddSexS").val();
	var userMAddPhone = $("#userMAddPhone").val();
	var userMAddMail = $("#userMAddMail").val();
	if (userMAddAccount == "") {
		alert("用户登陆账号不能为空！");
		return;
	}
	if (userMAddPasswd == "") {
		alert("用户登陆密码不能为空！");
		return;
	}
	if (userMAddName == "") {
		alert("用户姓名不能为空！");
		return;
	}
	if (userMAddUpTeamId == "defaultSelect") {
		alert("用户所属组织不能为空！");
		return;
	}

	request = new Object();
	request.operation = "addUser";
	request.jsonObject = new Object();
	request.jsonObject.account = userMAddAccount;
	request.jsonObject.passwd = userMAddPasswd;
	request.jsonObject.name = userMAddName;
	request.jsonObject.teamId = userMAddUpTeamId;
	request.jsonObject.isManager = userMAddIsManageS;
	request.jsonObject.sex = userMAddSexS;
	request.jsonObject.phone = userMAddPhone;
	request.jsonObject.email = userMAddMail;

	$.post("Gate", {
		req : JSON.stringify(request)
	}, function(data, status) {
		if (status == "success") {
			var resp = eval("(" + data + ')');
			if (resp.status == 0) {
				alert("添加用户 " + userMAddName + " 成功，用户名为：" + userMAddAccount
						+ "，密码为：" + userMAddPasswd + " ！");
				$("#page-wrapper").load("parts/userManage.html");
			} else {
				alert("添加用户失败，错误原因：" + resp.message);
			}
		} else {
			alert("HTTP请求异常，请重新登陆！");
			self.location = "login.html";
		}
	});

}

function doMDisUser(userId) {
	$("#page-wrapper")
			.load(
					"parts/userDis.html",
					function() {
						for (var i = 0; i < subUserList.length; i++) {
							if (subUserList[i].userId == userId) {
								document.getElementById('userDAvatar').innerText = subUserList[i].avatar;
								document.getElementById('userDId').innerText = subUserList[i].userId;
								document.getElementById('userDAccount').innerText = subUserList[i].account;
								document.getElementById('userDTeamName').innerText = subUserList[i].teamName;
								document.getElementById('userDIsManager').innerText = subUserList[i].isManager;
								document.getElementById('userDPhone').innerText = subUserList[i].phone;
								document.getElementById('userDEmail').innerText = subUserList[i].email;
								document.getElementById('userDSex').innerText = subUserList[i].sex;
							}
						}
						$("#userDisConButton")
								.html(
										"<button type=\"submit\" class=\"btn btn-default\" id=\"userEditSubmit\" onclick=\"doMEditUser("
												+ $("#userDId").text()
												+ ")\">修改</button>");
					});
}

function doMSetUserPasswd(userId) {
	var result = confirm("请确认重置ID为  " + userId + " 的用户密码！");
	if (result) {
		request = new Object();
		request.operation = "resetPasswd";
		request.jsonObject = new Object();
		request.jsonObject.userId = userId;
		request.jsonObject.newPasswd = "123456";
		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					// $("#showUser").html(resp.entity.name);
					alert("重置成功，密码为123456");
					$("#page-wrapper").load("parts/userManage.html");
				} else {
					alert("重置密码失败，错误原因：" + resp.message);
					$("#page-wrapper").load("parts/userManage.html");
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}

// 管理员修改所管理的用户的信息，加载界面及赋初始值
function doMEditUser(userId) {
	$("#page-wrapper")
			.load(
					"parts/userManageEdit.html",
					function() {
						request = new Object();
						request.operation = "getSubTeams";
						request.jsonObject = new Object();
						request.jsonObject.teamId = thisUser.teamId;
						$
								.post(
										"Gate",
										{
											req : JSON.stringify(request)
										},
										function(data, status) {
											if (status == "success") {
												var resp = eval("(" + data
														+ ')');
												if (resp.status == 0) {
													if (resp.entity != null) {
														subTeamList = resp.entity;
														for (var i = 0; i < subTeamList.length; i++) {
															$(
																	"#userMEUpTeamNameS")
																	.append(
																			"<option value="
																					+ subTeamList[i].teamId
																					+ ">"
																					+ subTeamList[i].teamName
																					+ "</option>");
														}
														for (var i = 0; i < subUserList.length; i++) {
															if (subUserList[i].userId == userId) {
																$(
																		"#userMEAccount")
																		.text(
																				subUserList[i].account);
																$("#userMEName")
																		.val(
																				subUserList[i].name);
																$(
																		"#userMEUpTeamNameS")
																		.val(
																				subUserList[i].teamId);
																$(
																		"#userMEIsManageS")
																		.val(
																				subUserList[i].isManager);
																$("#userMESexS")
																		.val(
																				subUserList[i].sex);
																$(
																		"#userMEPhone")
																		.val(
																				subUserList[i].phone);
																$("#userMEMail")
																		.val(
																				subUserList[i].email);

															}
														}
														$("#userMButton")
																.html(
																		"<button type=\"submit\" class=\"btn btn-default\" onclick=\"doUserMESubmitCon("
																				+ userId
																				+ ")\">修改</button><button type=\"submit\" class=\"btn btn-default\" onclick=\"doUserManageCan()\">取消</button>");
													} else {
														alert("GetSubTeams返回结果为空！");
													}
												} else {
													alert("GetSubTeams失败，错误原因："
															+ resp.message
															+ " 请重新登陆！");
													self.location = "login.html";
												}
											} else {
												alert("HTTP请求异常，请重新登陆！");
												self.location = "login.html";
											}
										});
					});
}

// 管理员修改用户信息页面的确认按钮动作
function doUserMESubmitCon(userIdTmp) {
	var userMEName = $("#userMEName").val();
	var userMEUpTeamId = $("#userMEUpTeamNameS").val();
	var userMEIsManageS = $("#userMEIsManageS").val();
	var userMESexS = $("#userMESexS").val();
	var userMEPhone = $("#userMEPhone").val();
	var userMEMail = $("#userMEMail").val();
	var userMEavatar = $("#userMEavatar").val();

	if (userMEIsManageS == "") {
		alert("是否管理员 不能为空！");
		return;
	} else if (userMEUpTeamId == "") {
		alert("所属组织 不能为空！");
		return;
	} else {
		request = new Object();
		request.operation = "chgUser";
		request.jsonObject = new Object();
		request.jsonObject.userId = userIdTmp;
		// request.jsonObject.account = thisUser.account;
		// request.jsonObject.passwd = thisUser.passwd;
		request.jsonObject.isManager = userMEIsManageS;
		request.jsonObject.teamId = userMEUpTeamId;
		request.jsonObject.name = userMEName;
		request.jsonObject.phone = userMEPhone;
		request.jsonObject.email = userMEMail;
		request.jsonObject.sex = userMESexS;
		// request.jsonObject.avatar = userMEavatar;
		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					$("#showUser").html(resp.entity.name);
					if (resp.entity != null) {
						alert("修改信息成功！");
						$("#page-wrapper").load("parts/userManage.html");
					} else {
						alert("修改信息失败，错误原因：" + resp.message);
						$("#page-wrapper").load("parts/userManage.html");
					}
				} else {
					alert("修改信息失败，错误原因：" + resp.message);
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}

function doMDelUser(userId) {
	var result = confirm("是否删除用户 " + userId + "？");
	if (result) {
		request = new Object();
		request.operation = "delUser";
		request.jsonObject = new Object();
		request.jsonObject.id = userId;
		$.post("Gate", {
			req : JSON.stringify(request)
		}, function(data, status) {
			if (status == "success") {
				var resp = eval("(" + data + ')');
				if (resp.status == 0) {
					alert("删除" + userId + "成功！");
					$("#page-wrapper").load("parts/userManage.html");
				} else {
					alert("删除用户失败，错误原因：" + resp.message);
					$("#page-wrapper").load("parts/userManage.html");
				}
			} else {
				alert("HTTP请求异常，请重新登陆！");
				self.location = "login.html";
			}
		});
	}
}
function showTable(data) {
	// alert(JSON.stringify(data));
	// $.fn.dataTable.ext.errMode = 'none';
	$('#userManageList-example')
			.DataTable(
					{
						"data" : data,
						"columns" : [
								{
									"data" : 'account',
									"width" : "50px",
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type == "display") {
											return "<tr class=\"odd gradeX\"><td class=\"center\">"
													+ data + "</td>";
										} else {
											return data;
										}
									}
								},
								{
									"data" : 'name',
									"render" : function(data, type, row, meta) {
										if (type === "display") {
											return "<td class=\"center\">"
													+ data + "</td>";
										}
										return data;
									}
								},
								{
									"data" : 'teamName',
									"width" : "120px",
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type == "display") {
											return "<tr class=\"odd gradeX\"><td class=\"center\">"
													+ data + "</td>";
										} else {
											return data;
										}
									}
								},
								{
									"data" : 'isManager',
									"width" : "50px",
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type == "display") {
											if (data == 0) {
												return "<tr class=\"odd gradeX\"><td class=\"center\">"
														+ "否" + "</td>";
											} else {
												return "<tr class=\"odd gradeX\"><td class=\"center\">"
														+ "是" + "</td>";
											}
										} else {
											return data;
										}
									}
								},
								{
									"data" : 'sex',
									"width" : "50px",
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type == "display") {
											return "<tr class=\"odd gradeX\"><td class=\"center\">"
													+ data + "</td>";
										} else {
											return data;
										}
									}
								},
								{
									"data" : 'phone',
									"width" : "60px",
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type == "display") {
											return "<tr class=\"odd gradeX\"><td class=\"center\">"
													+ data + "</td>";
										} else {
											return data;
										}
									}
								},
								{
									"data" : 'email',
									"width" : "70px",
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type == "display") {
											return "<tr class=\"odd gradeX\"><td class=\"center\">"
													+ data + "</td>";
										} else {
											return data;
										}
									}
								},
								{
									"data" : 'userId',
									"orderable" : false,
									"render" : function(data, type, row, meta) {
										if (type === "display") {
											return "<td><button type=\"submit\" class=\"btn btn-default\" onclick=doMDisUser("
													+ data
													+ ");>详情</button><button type=\"submit\" class=\"btn btn-default\" onclick=doMEditUser("
													+ data
													+ ");>修改</button><button type=\"submit\" class=\"btn btn-default\" onclick=doMDelUser("
													+ data
													+ ");>删除</button><button type=\"submit\" class=\"btn btn-default\" onclick=doMSetUserPasswd("
													+ data
													+ ");>重置密码</button>"
													+ "</td></tr>";
										}
										return '';
									}
								} ],
						"order" : [ 1, 'asc' ],
						"oLanguage" : {// 语言设置
							"sLengthMenu" : "每页显示 _MENU_ 条记录",
							"sZeroRecords" : "没有检索到数据",
							"sInfo" : "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
							"sInfoEmtpy" : "没有数据",
							"sProcessing" : '<i class="fa fa-coffee"></i> 正在加载数据...',
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "<span class=\"fa fa-chevron-left\">",
								"sNext" : "<span class=\"fa fa-chevron-right\">",
								"sLast" : "尾页"
							},
							"sSearch" : "搜索 "
						}
					});

	$('#userManageList-example').on('error.dt',
			function(e, settings, techNote, message) {
				// 这里可以接管错误处理，也可以不做任何处理
				// console.log( 'An error has been reported by DataTables: ',
				// message );
			}).DataTable();
}

function upLoadAvatar() {
	window.open("UploadAvatarTest/index.html");
}

function RefreshUpLoadAvatar() {
	var request = new Object();
	request.operation = "getUser";
	request.jsonObject = new Object();
	request.jsonObject.na = "na";
	var resp;
	$.ajax({
		type : "post",
		url : "Gate",
		data : {
			req : JSON.stringify(request)
		},
		async : false,
		success : function(data) {
			resp = eval('(' + data + ')');

		}
	});

	if (resp == null) {
		self.location = "login.html";
	} else {
		if (resp.entity != null) {
			thisUser = resp.entity;
			var imgTmp = "<img src=\"" + thisUser.avatar
					+ "\"width=\"100\" height=\"100\"/>";
			// $("#avatarImg").innerHTML=imgTmp;
			document.getElementById('avatarImg').innerHTML = imgTmp;
			alert("刷新头像成功！");
		} else {
			self.location = "login.html";
		}
	}
}